package com.miao.generator.dao;

import com.miao.entity.TableColumn;
import com.miao.entity.TableListEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GeneratorMapper {
    /**
     * 获取表内字段
     *
     * @param tableName 表名称
     * @return
     */
    @Select("select column_name, data_type, column_comment, IF(COLUMN_KEY = 'PRI', 1, 0) as is_primary\n" +
            "from information_schema.columns\n" +
            "where table_name = #{tableName}\n" +
            "  and table_schema = (select database())\n" +
            "order by ORDINAL_POSITION")
    public List<TableColumn> getTableColumn(String tableName);


    @Select("select table_name table_name, table_comment table_comment, create_time create_time from information_schema.tables\n" +
            "\t\t\twhere table_schema =(select database()) and TABLE_NAME not like '%generator' limit #{page},#{limit};")
    public List<TableListEntity> GetTableList(@Param("page") Integer page,
                                              @Param("limit") Integer limit);
}
